<?
require(PATH_CLASS."model.php");
class Form extends Model{	
	
	public function setFieldSet(){
		
		$fieldSet =  array(
							"aa"=>"FieldSet1",
							"bb1"=>"กำปั้นกับไม้มาลัยค้ำจุล"
						);

		parent::setModelFieldSet($fieldSet);
	}
	

	public function setButtonControlInput(){
		$arrayButton = array(
							"btn_save"=>array(
												"บันทึกข้อมูล",
												"submit"
											),
							/*"btn_close"=>array(
												"ออก",
												"button",
												"loadTab(".$this->tab.",'testModel','view')"
											)*/
							);
		parent::setModelButtonControlInput($arrayButton);
	}
	
	public function setButtonControlOutput(){
		$arrayButton = array("btn_edit"=>array("แก้ไขข้อมูล","button","loadTab(".$this->tab.",'testModel','form')"));
		parent::setModelButtonControlOutput($arrayButton);
	}
	
	public function setInput(){
		$query = "select * from test_tb where about_id='".$_POST["about_id"]."'";
		$arrayResult = Database::fetchArray(Database::query($query));

		$arrayInput["label"] = 'ชื่อ';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="text" class="span6 typeahead" name="member_name" value="'.$arrayOutputResultEdit["member_name"].'">';
		$arrayInput["input"] .= '<input type="hidden" name="member_id" value="'.$arrayOutputResultEdit["member_id"].'">';
		$arrayInput["input"] .= '<input type="hidden" name="old_member_id_id" value="'.$arrayOutputResultEdit["member_id"].'">';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["aa"][] = $arrayInput;

		/*$arrayInput["label"] = 'ชื่อ1';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="text" class="span6 typeahead" name="aaa" id="aaa" value=""/>';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["bb1"][] = $arrayInput;
		
		$arrayInput["label"] = 'ชื่อ2';
		$arrayInput["labelWidth"] = 15;
		$arrayInput["input"] = '<input type="text" class="span6 typeahead" name="aaa1" id="aaa" value=""/>';
		$arrayInput["inputWidth"] = 85;
		$arrayInput["required"] = true;
		$Input["aa"][] = $arrayInput;*/
		//$Input["NONE"][] = $arrayInput;
				
		parent::setModelInput($Input);
	}

	public function setValidate(){
		if($_POST["aa"]==""){
			parent::$checkValidate["aa"][] = "ต้องการค่า";
		}
		/*if($_POST["aaa"]==""){
			parent::$checkValidate["aaa"][] = "ต้องการค่า";
		}
		if($_POST["aaa1"]==""){
			parent::$checkValidate["aaa1"][] = "ต้องการค่า";
		}*/
	}

	public function setOutput(){
		$query = "select * from test_tb where about_id='".$_POST["about_id"]."'";
		$arrayResult = Database::fetchArray(Database::query($query));
		
		$arrayOutput["label"] = 'รหัส';
		$arrayOutput["labelWidth"] = 15;
		$arrayOutput["output"] = $arrayResult["about_id"];
		$arrayOutput["inputWidth"] = 85;
		$Output["NONE"][] = $arrayOutput;

		$arrayOutput["label"] = 'ชื่อ';
		$arrayOutput["labelWidth"] = 15;
		$arrayOutput["output"] = $arrayResult["about_name"];
		$arrayOutput["outputWidth"] = 85;
		$Output["NONE"][] = $arrayOutput;	

		parent::setModelOutput($Output);
	}

	public function insertData(){
		$about_id = Database::getLastValue('test_tb','about_id')+1;
		$arrayInsertData = array("about_id"=>$about_id,
								"about_name"=>$_POST["aa"]
								);
		$query = Database::getInsertData($arrayInsertData,"test_tb");
		//echo $query = Database::getUpdateData($arrayInsertData,"about","about_id=4");
		Database::query($query);
		//echo $query;
	}
}
?>
